package com.myspace.server.base.util;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * 响应封装
 * @author peng.zhang
 */
@Data
@Slf4j
public class JsonView {

    private String status;
    private Object content;
    private String errCode;
    private String errMsg;

    public void successPack(Object result) {
        this.setContent(result);
        this.setStatus(ConstantsEnum.JSON_VIEW_STATUS_SUCCESS.getKey());
        this.setErrCode("");
        this.setErrMsg("");
    }

    public void errorPack(String errorLog, Exception e) {
        log.error(errorLog + e.getMessage());
        this.setStatus(ConstantsEnum.JSON_VIEW_STATUS_ERROR.getKey());
        this.setContent("");
        this.setErrCode(ErrorCodeEnum.ERROR_SYSTEM_ERROR.getErrCode());
        this.setErrMsg(ErrorCodeEnum.ERROR_SYSTEM_ERROR.getErrMessage());
    }

}
